package server.commonData;

import java.util.HashMap;
import java.util.Map;

import server.msgBean.LoginMessage.RoomInfo;
import server.msgBean.LoginMessage.RoomInfoList;

/**
 * 房间管理类
 * @author King
 *
 */
public class RoomManager
{
	/**房间Map**/
	public Map<String, Room> rooms = new HashMap<String, Room>();
	
	public RoomManager()
	{
		createRoom();
	}
	
	/**
	 * 创建房间
	 */
	private void createRoom()
	{
		Room xinshou = new Room("新手房间",10);
		this.rooms.put(xinshou.getRoomName(), xinshou);
		xinshou.init();
		Room zhongji = new Room("中级房间",20);
		this.rooms.put(zhongji.getRoomName(), zhongji);
		zhongji.init();
		Room gaoji = new Room("高级房间",30);
		this.rooms.put(gaoji.getRoomName(), gaoji);
		gaoji.init();
	}
	
	/**
	 * 根据房间名称获得房间对象
	 * @param roomName
	 * @return
	 */
	public Room getRoom(String roomName)
	{
		return this.rooms.get(roomName);
	}
	
	/**
	 * 显示房间信息 给客户端
	 * @param builder
	 */
	public void showRoomInfo(RoomInfoList.Builder builder)
	{
		for(Map.Entry<String, Room> entry:this.rooms.entrySet())
		{
			RoomInfo.Builder roomInfo = RoomInfo.newBuilder();
			roomInfo.setRoomName(entry.getKey());
			entry.getValue().showRoomInfo(roomInfo);
			builder.addRoomInfo(roomInfo);
		}
	}
	
}
